import {arrayToMap, deleteSql, insertSql, objectToMap, selectSql, updateSql} from "../util/sqlUtils";
import {BugEntering} from "../sql/domin";


export class InputMapper {

    public static async selectInputListByUserId(userId:number) {
        return selectSql('bug_entering',new Map([
            ['userId',userId]
        ]))
    }

    public static async selectInputListByDeptId(deptId:number) {
        return selectSql('bug_entering',new Map([
            ['deptId',deptId]
        ]),'order by createTime desc')
    }

    public static selectInputById(inputId:Number){
        return selectSql('bug_entering',
            new Map<string, any>([
                ['id',inputId]
            ]))
    }

    public static selectInputByUId(uId:string){
        return selectSql('bug_entering',
            new Map<string, any>([
                ['uId',uId]
            ]))
    }

    // 将几天之前的数据删除
    public static deleteInputByDay(day: number) {
        return deleteSql('bug_entering',
            `where date('now','-${day} day') >= date(createTime)`)
    }

    public static deleteInputById(id:number) {
        return deleteSql('bug_entering',
            `where id = ${id}`)
    }

    public static deleteInputByUid(uId:string) {
        return deleteSql('bug_entering',
            `where uId = ${uId}`)
    }

    public static insertInputList(bugEntering: BugEntering[]) {
        return insertSql('bug_entering', arrayToMap(bugEntering))
    }

    public static insertInput(bugEntering: BugEntering) {
        return insertSql('bug_entering', objectToMap(bugEntering))
    }

    public static updateInput(bugEntering: BugEntering) {
        return updateSql('bug_entering', objectToMap(bugEntering), 'where id = '+bugEntering.id)
    }

    public static updateInputByUId(bugEntering: BugEntering) {
        return updateSql('bug_entering', objectToMap(bugEntering), 'where uId = '+bugEntering.uId)
    }

}
